home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8551 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  61 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!news1!news
  3. From: koconnor@iquest.net (Kevin O'Connor)
  4. Subject: HELP: Pointer to member involving unions
  5. X-Nntp-Posting-Host: edge.iquest.net
  6. Message-ID: <DMw50M.zM@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Reply-To: koconnor@iquest.net
  9. Organization: Edge Software Services Inc.
  10. X-Newsreader: NeoLogic News for OS/2 [version: 4.5 Build YJ 048]
  11. Date: Fri, 16 Feb 1996 22:55:34 GMT
  12.  
  13. Can anyone tell me why the last line of this example won't compile?
  14.  
  15. struct Registers {
  16.     union {
  17.         short bc;
  18.         struct {
  19.             char b;
  20.             char c;
  21.         } bc8;
  22.     };
  23. };
  24.  
  25. class Proc : public Registers {
  26.     static short Proc::*Test1;
  27.     static char Proc::*Test2;
  28. };
  29.  
  30. short Proc::*Proc::Test1 = &Proc::bc;    // No error
  31. char Proc::*Proc::Test2 = &Proc::bc8.b;    // Error: bc8 cannot be used w/o
  32. object
  33.  
  34. I've tried this on a couple of compilers. My IBM C/Set++ 2.0 gives me the
  35. following errors:
  36.  
  37.    16       |short Proc::*Proc::Test1 = &Proc::bc;
  38. cpptest.cpp(16:1) : error EDC3055: "short union {...}::*" cannot be converted
  39. to
  40.  "short Proc::*".
  41.    17       |char Proc::*Proc::Test2 = &Proc::bc8.b;
  42. cpptest.cpp(17:1) : error EDC3078: Non-static member "Registers::union
  43. {...}::bc
  44. 8" must be associated with an object or a pointer to an object.
  45. cpptest.cpp(17:1) : error EDC3055: "char*" cannot be converted to "char
  46. Proc::*"
  47.  
  48. My borland C++ 2.0 for OS/2 (equivalent to Borland C++ 3.1 for Windows) gives
  49. me the following:
  50.  
  51. Error cpptest.cpp 17: Member bc8 cannot be used without an object
  52. *** 1 errors in Compile ***
  53.  
  54. ------------------------------------------
  55. Kevin O'Connor
  56. Edge Software Services Inc.
  57. koconnor@iquest.net
  58. http://www.iquest.net/~koconnor/
  59. ------------------------------------------
  60.  
  61.